//
//  RTJOpinionController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/14.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJOpinionController.h"

@interface RTJOpinionController ()<UITextFieldDelegate,UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *labs;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIView *bg_View;
@property (weak, nonatomic) IBOutlet UIView *bg_View2;
@property (weak, nonatomic) IBOutlet UITextField *txtFld;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewTop;

@end

@implementation RTJOpinionController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"意见反馈";
    
     self.viewTop.constant = screenH == 812 ? 88 : 64;
    _textView.delegate = self;
    _txtFld.delegate = self;
    _labs.text = @"请详细描述您的问题或建议，我们将及时跟进解决。";
    
    [self backview:_bg_View viewOfcornerRadius:5];
    [self backview:_bg_View2 viewOfcornerRadius:5];
    
    
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    
    if (textView.text.length == 0) {
        
        _labs.text = @"请详细描述您的问题或建议，我们将及时跟进解决。";

    }else{
        
        _labs.text = @"";

    }
    
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    
    _labs.text = @"";
    
}

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    
    
    
}

-(void)backview:(UIView *)backview viewOfcornerRadius:(NSInteger)cornerRadius{
    
    backview.layer.cornerRadius = cornerRadius;
    backview.layer.shadowColor = [UIColor colorForHex:@"#dbc9cc"].CGColor;
    backview.layer.shadowOffset = CGSizeMake(-1, 1);
    backview.layer.shadowOpacity = 0.5;
    backview.layer.shadowRadius = 5;
    
}


- (IBAction)tijiao:(id)sender {
    
    [_textView resignFirstResponder];
    [_txtFld resignFirstResponder];
    
    if (![Apputil validatePhoneWithString:_txtFld.text] ) {
        
        [SVProgressHUD showErrorWithStatus:@"请正确填写电话号码"];
        return;
    }
    
    [SVProgressHUD showWithStatus:nil];
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"mobile":_txtFld.text}];
    
    if (_textView.text.length!=0) {
        
        [dic setObject:_textView.text forKey:@"content"];
    }
    
    [RTJNetWork asyncRequestWithURL:@"init/feedback" params:dic method:POST zxCompletion:^(id data, NSInteger status, BOOL success, NSString *errorMsg) {
        
        [SVProgressHUD dismiss];
        if (success) {
            
            if ([data[@"status"]integerValue] == 1) {
                
                [SVProgressHUD showSuccessWithStatus:@"意见提交成功，感谢您的反馈"];
                [self.navigationController popViewControllerAnimated:YES];
                
            }else{
                
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",data[@"msg"]]];
                
            }
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",errorMsg]];
            
        }
    }];
}

@end
